<?php 
$ac = $_POST['ac'];
//adminmessage('a');exit;
if (empty($ac)) {
	@include S_ROOT.'dataconfig.php';
	$_CONFIG['mailtitle'] = str_replace('\\','',$_CONFIG['mailtitle']);
	$_CONFIG['mailcontent'] = str_replace('\\','',$_CONFIG['mailcontent']);
	include atemplate('do_system');
}elseif ($ac == 'sendmail') {
	$server = trim($_POST['server']);
	$email = trim($_POST['email']);
	$password = trim($_POST['password']);
	$guessallnum = intval($_POST['guessallnum']);
	$guesssimplenum = intval($_POST['guesssimplenum']);
	if (empty($server) || empty($email) ||empty($password)) {
		adminmessage('请正确填写');
	}
	if (!isemail($email)) {
		adminmessage('邮件格式错误');
	}
	
	$starttime = $_POST['starttime'];
	$endtime = $_POST['endtime'];

	$mailtitle = $_POST['mailtitle'];
	$mailcontent = $_POST['mailcontent'];



	$_config = array('server'=>$server,'email'=>$email,'password'=>$password,'guessallnum'=>$guessallnum,'guesssimplenum'=>$guesssimplenum,'mailtitle'=>$mailtitle,'mailcontent'=>$mailcontent,'starttime'=>$starttime,'endtime'=>$endtime);
	

	$configstr = "<?php\r\n\$_CONFIG=".var_export($_config,true).";\r\n?>";
	file_put_contents(S_ROOT.'dataconfig.php',$configstr);
	adminmessage('操作成功','/admin/index.php?do=system');
}elseif ($ac == 'password') {
	$old_password = trim($_POST['old_password']);
	$new_password = trim($_POST['password']);
	$new_password1 = trim($_POST['password1']);
	if(!empty($old_password) && !empty($new_password) && $new_password == $new_password1) {
		$password = $db->result($db->query("select password from ".tname('admin')." where username = 'admin'"),0);
		var_dump($password);
		if(md5($old_password) == $password) {
			updatetable('admin',array('password'=>md5($new_password)),array('username'=>'admin'));
			adminmessage('修改密码成功');
		} else {
			adminmessage('原始密码不对');
		}
	}else{
		adminmessage('密码格式错误');
	}
}
?>